package com.PuzGame.combinenumbers;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import android.content.Context;
import android.content.SharedPreferences;

public class Tools {
	
	private final static String DATE_FORNMAT = "yyyyMMdd_HHmmss";
	
	public static String DateToString(Date date)
	{
		String StringDate ="";	
		if(date!=null)
		{
			SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORNMAT);
			StringDate = sdf.format(date);
		}
		return StringDate;
	}
	
	public static Date StringToDate(String string)
	{
		SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORNMAT);
		try {
			return sdf.parse(string);
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}
	
	
	public static GeneralSettings RestoreGS(Context c)
	{
		GeneralSettings gs = new GeneralSettings();
		SharedPreferences settings = c.getSharedPreferences("GeneralSettings", c.MODE_PRIVATE);

		gs.setSFX(settings.getBoolean("SFX", false));
		gs.setKeepAwake(settings.getBoolean("KeepAwake", true));
		gs.setQuickPlayMode(settings.getBoolean("QuickPlayMode", false));
		gs.setVibration(settings.getBoolean("Vibration", false));

		return gs;
	}

	
	

	public static int RestoreUserMaxLevel(Context c) {
		SharedPreferences settings = c.getSharedPreferences("SaveInfo", c.MODE_PRIVATE);
		return settings.getInt("MaxStageNo", 1);
	}
	
	public static float GetUserRank(long winningPoints, float losingPoints)
	{
		float rank = 0;
		
		if(winningPoints + losingPoints != 0)
		{
			rank = (100*winningPoints)/(winningPoints + losingPoints);
		}
		return rank;
	}
	
	public static long GetUserScore(float rank, int stage)
	{
		return (long)(rank*stage);
	}

}
